//
//  OtherMainViewController.swift
//  AirTravel
//
//  Created by apple on 2021/11/16.
//

import UIKit
import Parchment
class OtherMainViewController: UIViewController {

    var flag = 0
    var dataArr :[String] =  ["接送机","道路救援","租车"]
    override func viewDidLoad() {
        super.viewDidLoad()

        setUppagingView()
        // Do any additional setup after loading the view.
    }
    
    
  
    @IBAction func backClick(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }
    
    
    func setUppagingView() {
        addChild(self.pagingView)
        self.view.addSubview(self.pagingView.view)
        self.pagingView.view.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.right.equalToSuperview().offset(-16)
            make.top.equalToSuperview().offset(180)
            
            make.bottom.equalToSuperview().offset(0)
        }
        self.pagingView.didMove(toParent: self)
        self.pagingView.select(index: flag)

    }
    
    lazy var pagingView: PagingViewController = {
        let pagingViewController = PagingViewController()
        pagingViewController.dataSource = self
        pagingViewController.delegate = self
//        pagingViewController.menuItemSize = .selfSizing(estimatedWidth: self.view.frame.size.width / 3, height: 40)
        
//        pagingViewController.select(index: 2)
        pagingViewController.font = UIFont.systemFont(ofSize: 14)
        pagingViewController.selectedFont = UIFont.boldSystemFont(ofSize: 17)
        pagingViewController.selectedTextColor = UIColor.init(hexString: "333333")
        pagingViewController.indicatorColor = UIColor.init(hexString: "FF8A00")
//        pagingViewController.menuItemLabelSpacing = 20
        pagingViewController.indicatorOptions = .visible(
          height: 1,
          zIndex: Int.max,
          spacing: UIEdgeInsets.init(top: 0, left: 12, bottom: 0, right: 12),
          insets: UIEdgeInsets.zero
        )
        return pagingViewController
    }()

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension OtherMainViewController: PagingViewControllerDataSource,PagingViewControllerDelegate {
  func pagingViewController(_: PagingViewController, pagingItemAt index: Int) -> PagingItem {
   
    return PagingIndexItem(index: index, title:dataArr[index])
    
  }
  
  func pagingViewController(_: PagingViewController, viewControllerAt index: Int) -> UIViewController {
    
    let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ZCViewController") as! ZCViewController
    vc.type = index
     return vc
  }
  
  func numberOfViewControllers(in pagingViewController: PagingViewController) -> Int {
    return 3
  }
    
    func pagingViewController(
      _ pagingViewController: PagingViewController,
      didScrollToItem pagingItem: PagingItem,
      startingViewController: UIViewController?,
      destinationViewController: UIViewController,
        transitionSuccessful: Bool){
        if transitionSuccessful {
//            let item = pagingItem as! PagingIndexItem
//            if let array = self.leftDatas {
//                let dic = array[item.index] as! Dictionary<String,Any>
//                self.category_id = "\(dic["id"] ?? "")"
//                self.sonArray = dic["son"] as? Array<Any>
//                NotificationCenter.default.post(name: NSNotification.Name("ClassificationNotification"), object: nil, userInfo: ["id":self.category_id,"list":self.sonArray ?? [],"search":self.search])
//            }
//
        }
    }
}
